package com.zhangxiaofanfan.hotcode.fourth.third;

/**
 *
 * @date 2024-07-13 03:14:13
 * @author zhangxiaofanfan
 */
public class HotCode078 {
    public static void main(String[] args) {
        HotCode078 hotCode = new HotCode078();
        int[] nums = {3,2,1,1,4};
        System.out.println(hotCode.canJump(nums));
    }

    public boolean canJump(int[] nums) {
        int maxIndex = 0;
        for (int i = 0; i < nums.length; i++) {
            if (i > maxIndex) {
                return false;
            }
            if (maxIndex >= nums.length - 1) {
                return true;
            }
            maxIndex = Math.max(maxIndex, i + nums[i]);
        }
        return true;
    }
}
